package com.vids.utils;


import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.StrUtil;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateTransUtils {

    public static String timeFormat(Date date) {
        if(date == null) {
            date = new Date();
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        return sdf.format(date);
    }

    public static String timeTrans(String date) {
        if(date == null) {
            return null;
        }
        int len = date.length();
        // 14位时间 直接返回yyyyMMddHHmmss
        if(len == 14){
            return date;
        }
        // 13位时间戳
        if(len == 13){
            Instant instant = Instant.ofEpochMilli(Long.parseLong(date));
            date = instant.atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        }
        // 10位时间戳
        if (len == 10) {
            Instant instant = Instant.ofEpochSecond(Long.parseLong(date));
            date = instant.atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        }
        // yyyyMMdd || yyyyMMddHHmm
        if(len == 8 || len == 12){
//            date = CharSequenceUtil.(date, 14, '0');
        }
        return date;
    }

//    public static void main(String[] args) {
//        String date_time ="2024-06-02T22:16:37+08:00";
//        StringBuffer sb = new StringBuffer();
//        String strDateTime =sb.append(date_time.substring(0,4))
//                         .append(date_time.substring(5,7)).append(date_time.substring(8,10))
//                         .append(date_time.substring(11,13)).append(date_time.substring(14,16))
//                         .append(date_time.substring(17,19)).toString();
//
//        System.out.println("strDateTime="+strDateTime);
//    }

}
